<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.13"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>OpenMesh: Using custom properties (old style)</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="logo_align.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectlogo"><img alt="Logo" src="rwth_vci_rgb.jpg"/></td>
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">OpenMesh
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.13 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('a04345.html','');});
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="headertitle">
<div class="title">Using custom properties (old style) </div>  </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><p>This small code example shows how to attach and access additional properties on a mesh.</p>
<p><em>Note that this is an old style of using properties. Nowadays you should use the <a class="el" href="a02597.html" title="This class is intended to manage the lifecycle of properties. ">OpenMesh::PropertyManager</a> instead.</em></p>
<p>When you want to add an additional properties you have to attach it to a primitive of the mesh. You can attach to verticies, halfedges, edges, faces or to the mesh itself. Use the add_property function:</p>
<div class="fragment"><div class="line"><span class="comment">// for each vertex an extra double value</span></div><div class="line"><a class="code" href="a02553.html">OpenMesh::VPropHandleT&lt; double &gt;</a> vprop_double;</div><div class="line">mesh.add_property( vprop_double ,<span class="stringliteral">&quot;Vertex property name&quot;</span>);</div><div class="line"></div><div class="line"><span class="comment">// for each halfedge an extra int value</span></div><div class="line">OpenMesh::HEPropHandleT&lt; int &gt; heprop_int;</div><div class="line">mesh.add_property( heprop_int ,<span class="stringliteral">&quot;Halfedge property name&quot;</span>);</div><div class="line"></div><div class="line"><span class="comment">// for each edge an extra float value</span></div><div class="line"><a class="code" href="a02561.html">OpenMesh::EPropHandleT&lt; float &gt;</a> eprop_float;</div><div class="line">mesh.add_property( eprop_float ,<span class="stringliteral">&quot;Edge property name&quot;</span>);</div><div class="line"></div><div class="line"><span class="comment">// for each face an extra double value</span></div><div class="line"><a class="code" href="a02565.html">OpenMesh::FPropHandleT&lt; double &gt;</a> fprop_double;</div><div class="line">mesh.add_property( fprop_double ,<span class="stringliteral">&quot;Face property name&quot;</span>);</div><div class="line"></div><div class="line"><span class="comment">// for the mesh an extra string</span></div><div class="line"><a class="code" href="a02569.html">OpenMesh::MPropHandleT&lt; string &gt;</a> mprop_string;</div><div class="line">mesh.add_property( mprop_string , <span class="stringliteral">&quot;Mesh property name &quot;</span>);</div></div><!-- fragment --><p>Accessing to the property is available via the property function. This function gets the property handle (created above) and a handle (e.g. to a vertex or a face):</p>
<div class="fragment"><div class="line"><span class="comment">// Write something to a face property:</span></div><div class="line">mesh-&gt;property( &lt;FaceProperty&gt; , &lt;FaceHandle&gt; ) = &lt;<span class="keyword">new</span> value&gt;;</div><div class="line"></div><div class="line"><span class="comment">// E.g.</span></div><div class="line"><span class="keywordflow">for</span> (f_it=mesh-&gt;faces_begin(); f_it!=mesh-&gt;faces_end()  ; ++f_it) {</div><div class="line">  mesh-&gt;property( fprop_double , *f_it ) = 0.0;</div><div class="line">}</div></div><!-- fragment --><p>As you can attach properties to the mesh, you might want to add a property in one function and access it in another, where the handle is not yet available. You can retrieve the required handle in the following way (Note that the handles are accessed by their name and type):</p>
<div class="fragment"><div class="line"><span class="comment">// Specify handle type (Double face handle in this case):</span></div><div class="line"><a class="code" href="a02565.html">OpenMesh::FPropHandleT&lt; double &gt;</a> fprop_double;</div><div class="line"></div><div class="line"><span class="comment">// Try to get handle with the given name.</span></div><div class="line"><span class="keywordflow">if</span> ( !mesh_.get_property_handle(fprop_double,<span class="stringliteral">&quot;Face property name&quot;</span>) )  {</div><div class="line">  std::cerr &lt;&lt; <span class="stringliteral">&quot;Unable to retrieve property! &quot;</span> &lt;&lt; std::endl;</div><div class="line">  <span class="keywordflow">return</span></div><div class="line">}</div><div class="line"></div><div class="line"><span class="comment">// If we reach this point, we have a valid handle.</span></div></div><!-- fragment --><p>The properties can be removed by calling remove_property:</p>
<div class="fragment"><div class="line"><span class="comment">// Remove the property</span></div><div class="line">mesh-&gt;remove_property(fprop_double);</div></div><!-- fragment --><p>A useful function to see all properties on the mesh is:</p>
<div class="fragment"><div class="line"><span class="comment">// Print all available properties</span></div><div class="line">mesh-&gt;property_stats();</div></div><!-- fragment --><p>A useful class for handling properties and their lifetime is the <a class="el" href="a02597.html" title="This class is intended to manage the lifecycle of properties. ">OpenMesh::PropertyManager</a>. </p>
</div></div><!-- contents -->
</div><!-- doc-content -->
<hr>
<address>
<small>
<a href="http://www.rwth-graphics.de" style="text-decoration:none;">
</a>
Project <b>OpenMesh</b>, 
&copy;&nbsp; Computer Graphics Group, RWTH Aachen.
Documentation generated using 
<a class="el" href="http://www.doxygen.org/index.html">
<b>doxygen</b>
</a>.
</small>
</address>
</body>
</html>
